﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Noris.Tools.FrxEditor.Components
{
    /// <summary>
    /// Panel, který zajišťuje zobrazení PDF souboru
    /// </summary>
    public class PdfViewPanel : DPanel
    {
        /// <summary>
        /// Konstruktor
        /// </summary>
        public PdfViewPanel()
        {
            this.Initialize();
        }
        protected override bool IsInputKey(Keys keyData)
        {
            if (keyData == Keys.Escape)
            { }
            return base.IsInputKey(keyData);
        }
        protected void Initialize()
        {
            this.AxAcroPdf = new AxAcroPDFLib.AxAcroPDF();

            this.AxAcroPdf.BeginInit();

            this.AxAcroPdf.Name = "AxAcroPdf";
            this.AxAcroPdf.Dock = System.Windows.Forms.DockStyle.Fill;
            // this.AxAcroPdf.setShowToolbar(false);       Před koncem inicializace NELZE !!!

            this.Controls.Add(this.AxAcroPdf);

            this.AxAcroPdf.EndInit();
        }
        /// <summary>
        /// Prohlížeč ADOBE
        /// </summary>
        private AxAcroPDFLib.AxAcroPDF AxAcroPdf;
        /// <summary>
        /// Zajistí zobrazení PDF dat do controlu
        /// </summary>
        /// <param name="content"></param>
        /// <param name="fileName"></param>
        public void LoadContent(byte[] content, string fileName)
        {
            string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "acro");
            if (!System.IO.Directory.Exists(tempPath))
                System.IO.Directory.CreateDirectory(tempPath);
            string tempFile = System.IO.Path.Combine(tempPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".pdf");
            System.IO.File.WriteAllBytes(tempFile, content);

            this.LoadFile(tempFile);
        }
        /// <summary>
        /// Zajistí načtení souboru PDF do controlu
        /// </summary>
        /// <param name="file"></param>
        public void LoadFile(string file)
        {
            // select cislo_subjektu from lcs.product_order
            
            this.AxAcroPdf.LoadFile(file);
            this.AxAcroPdf.setShowToolbar(false);
        }
    }
}
